﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Buyer
{
    public partial class wfReleaseForum : msBsc.Cls.BPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //this.SetContrlValue("txtTempUrl", GetFormParam("T_URL"));
                //this.ExecJScript("doBoundContent('" + "/Template/" + GetFormParam("T_URL") + "');");
            }
        }

        private void publishingForum()
        {
            string forumTitle = this.GetParamHtValue("forumTitle");
            string forumInfo = this.GetParamHtValue("forumInfo");
            string publishId = msBsc.SvRef.UserInfo.Operator;
            if (string.IsNullOrEmpty(forumTitle))
            {
                this.Alert("标题不能为空");
                return;
            }
            if (string.IsNullOrEmpty(forumInfo))
            {
                this.Alert("发布内容不能为空");
                return;
            }
            if (string.IsNullOrEmpty(publishId))
            {
                this.ExecJScript(@"window.location.href = ""/""");
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizSourcePosts sourcePosts=new AppLogic.DataAlc.CBizSourcePosts())
            {
                string[] ret = sourcePosts.AddSourcePosts(publishId, forumTitle, forumInfo);
                if (ret[0] == "OK")
                {
                    this.ExecJScript(@"alert('发布成功');$('#title').val('');
                        $('#forumInfo').val();
                        KindEditor.html('#forumInfo', '');");
                }
                else {
                    this.Alert(ret[1]);
                }
            }
        }

        //private void doSaveSet()
        //{
        //    string strHeadHtml = this.GetPostHtValue("TEMPLATE_HTML");
        //    string strVpath = "/Template/" + this.GetPostHtValue("TEMPLATE_URL");//只是文件名，目录固定
        //    if (strHeadHtml != string.Empty && strVpath != string.Empty)
        //    {
        //        string strFFullPath = System.Web.HttpContext.Current.Server.MapPath(strVpath);
        //        System.IO.File.WriteAllText(strFFullPath, strHeadHtml, System.Text.Encoding.UTF8);
        //    }
        //    //保存路径
        //    this.ExecJScript("layer.msg('成功保存模版！',1,{type:1,shade:false});");

        //}

        public override void DoAction()
        {
            if (this.strAction == "published")
            {
                publishingForum();
            }
            //if (this.strAction=="doSaveSet")
            //{
            //    doSaveSet();
            //}
        }
    }
}